﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.ComponentModel.Composition;
using Microsoft.Practices.ServiceLocation;
using System.Windows.Media;

namespace Dynamic_UI_Framework
{
    [Export(typeof(TabControlRegionAdapter))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class TabControlRegionAdapter : AdapterBase<IRegion, TabControl>
    {
        protected override void Adapt(IRegion codon, TabControl target)
        {
            Region r = codon as Region;
            r.Target = target;

            target.ContextMenu = new ContextMenu();
            MenuItem add = new MenuItem { Header = "TabItem" };
            add.Click += (s, e) =>
                {
                    var adapter = ServiceLocator.Current.GetInstance<TabItemRegionAdapter>();
                    TabItem ti = new TabItem { Header = "测试", Background = Brushes.SandyBrown };
                    target.Items.Add(adapter.Initialize(ti,"asdf").Target);
                };
            target.ContextMenu.Items.Add(add);
        }

        protected override IRegion Create()
        {
            return new Region();
        }
    }
}
